package cn.dengta.webapp.user.model;

import cn.dengta.common.context.I18N;
import cn.dengta.common.model.*;
import cn.dengta.context.model.UserEnumI18nKey;

/**
 * 证件类型枚举
 */
public enum CertType implements VisibleProxyImpl<CertType, Integer> {
	/** 身份证 */
	ID_CARD(1, true, UserEnumI18nKey.CERT_TYPE_ID_CARD),
	/** 港澳身份证 */
	ID_CARD_OF_COMPATRIOT(2, true, UserEnumI18nKey.CERT_TYPE_ID_CARD_OF_COMPATRIOT),
	/** 护照 */
	PASSPORT(3, true, UserEnumI18nKey.CERT_TYPE_PASSPORT),
	/** 军官证 */
	CERT_OF_OFFICER(4, true, State.PRIVATE, UserEnumI18nKey.CERT_TYPE_CERT_OF_OFFICER),
	/** 营业执照 */
	BUSINESS_LICENSE(11, false, State.PRIVATE, UserEnumI18nKey.CERT_TYPE_BUSINESS_LICENSE),
	/** 其它 */
	OTHER(99, true, State.PRIVATE, UserEnumI18nKey.CERT_TYPE_OTHER)
	//
	;

	// 定义私有变量
	public final Integer value;
	final ValueProxy<CertType, Integer> proxy;
	public final boolean personal;

	// 构造函数，枚举类型只能为私有
	CertType(Integer value, boolean personal, State state, String label) {
		this.value = value;
		this.personal = personal;
		this.proxy = new ValueProxy<>(this, state, value, label);
	}

	CertType(Integer value, boolean personal, String label) {
		this(value, personal, State.PUBLIC, label);
	}

	@Override
	public ValueProxy<CertType, Integer> getProxy() {
		return proxy;
	}

	public String getLabel() {
		return I18N.msg(proxy.label);
	}

	private static CertType[] protectedValues;

	public static CertType[] getValues() {
		return ValueProxy.getCachedArray(CertType.class, CertType::values);
	}

	public static CertType[] getProtectedValues() {
		CertType[] array = protectedValues;
		if (array == null) {
			protectedValues = array = ValueProxy.getVisibleEnums(CertType.class, getValues(), State.PROTECTED);
		}
		return array;
	}

	public static CertType of(Integer val) {
		return ID_CARD.getValueOf(val);
	}

	public boolean isPersonal() {
		return personal;
	}

	@Override
	public Integer getValue() {
		return value;
	}

}
